//领导日程安排日历渲染
var initLdRcap;
var jsonLdRCList;
var laydate ;
//日程数据处理
var jsonGrRCList ;
var wld ;
$(document).ready(function () {
    layui.use(['layer','jquery', 'table', 'element', 'laydate','carousel'], function () {
        var layer = layui.layer,
    	$ = layui.jquery;
        var table = layui.table;
        var element = layui.element;
         laydate = layui.laydate;
        var carousel = layui.carousel;

      //页面一打开就执行弹层
        getWldList();
    });
});
function formatJson(jsonData){
    var json = "{";
    for (var i = 0; i < jsonData.length; i++) {
        if(i == jsonData.length -1 ){
            json = json + '"' + jsonData[i].dateStr + '"' + ":" +'""'
        }else{
            json = json + '"' + jsonData[i].dateStr + '"' + ":" +'"",'
        }
    }
    json = json + "}";
    var jsonPar = JSON.parse(json);
    return jsonPar;
}


function initLdRc(jsonLdRCList){
    initLdRcap = laydate.render({
        elem: "#layDate_ld"
        , position: "static"
        , showBottom: false
        , theme: "default"
        , mark: formatJson(jsonLdRCList)
        ,ready: function(date){
            bindFu(jsonLdRCList);
        }
        , done: function (value, date) {
            /*var theme = "<ul class='layer_notice'>";
            var count = 1;
            for (var i = 0; i < jsonLdRCList.length; i++) {
                if (value === jsonLdRCList[i].dateStr) { //点击2017年8月15日，弹出提示语
                    theme += '<li style="text-align: left;"><div class="rcdiv">' + count + "、" + jsonLdRCList[i].theme + '</div></li>';
                    count++;
                }
            }
            theme+="</ul>";
            if (theme != "<ul></ul>") {
                //initLdRcap.hint(theme);
                openTip(theme);
            }*/
        }
    });
}


//根据code查询领导日程信息
function getLdData(userCode){
    $.ajax({
        type: "get",
        url: window.ViewContextPath + "system/layui/getSchedule?userCode="+userCode,
        async:false,
        dataType: "json",
        success: function(data){
            jsonLdRCList = data.data;
        }
    });
}

//获取委领导信息
function getWldList(){
    $.ajax({
        type: "get",
        url: window.ViewContextPath +"system/layui/getWldList",
        async:false,
        dataType: "json",
        success: function(data){
            wld = data.data;
            $("#wldName").html(wld[0].userName);
            $("#wldListOpt").html(wld[0].userCode);
            var userCode = wld[0].userCode;
            $('#layDate_ld').empty();
            getLdData(userCode);
            initLdRc(jsonLdRCList);
        }
    });
}
//更多日程安排
function moreSchedule() {
    var url=window.nginxpath+"oa/modules/doc/schedule/schedule.jsp?flag=T";
    parent.openDiv("1220px","600px",url,"厅局级领导日程活动");
}
//更多通知公告
function moreTzggInfo(datatype) {
   // parent.openDiv("1000px","600px",window.ViewContextPath + "system/messageInfo/listMessageInfo","通知公告");
    window.open(window.ViewContextPath + "modules/dashboard/messageinfo/public.jsp?datatype="+datatype);
}
//拥有tab页的更多
function moreTzggInfoMore(id) {
    var tabName=$(id).parent().parent().find('.layui-this').html();
    var datatype="";

    if(tabName=="学习心得"){
        datatype="3";
    }else if(tabName=="培训教材"){
        datatype="4";
    }else if(tabName=="出国公示"){
        datatype="7";
    }else if(tabName=="表彰公示"){
        datatype="8";
    }else if(tabName=="考核公示"){
        datatype="9";
    }
    /*openDiv("1000px","600px",window.ViewContextPath + "system/messageInfo/listMessageInfo?dataType="+dataType,"通知公告");*/
    window.open(window.ViewContextPath + "modules/dashboard/messageinfo/public.jsp?datatype="+datatype);
}
function changeWld(userCode,userName){
    $('#layDate_ld').empty();
    $("#wldName").html(userName);
    $("#wldListOpt").html(userCode);
    getLdData(userCode);
    initLdRc(jsonLdRCList);
}
function getWlds(){
    openDiv("350px","400px",window.ViewContextPath +"system/layui/toWldPage","委领导");
}
//iframe情况下弹出
function parentShowMessageInfo(url,title){
    /*parent.openDiv("900px", "500px",  window.ViewContextPath+url, title);*/
    window.open(window.nginxpath+url);
}
function bindFu(jsonRCList) {
    $(".laydate-day-mark").parent().mouseover(function () {
        var value=$(this).attr("lay-ymd");
        var count = 1;
        var theme = "<ul class='layer_notice'>";
        for (var i = 0; i < jsonRCList.length; i++) {
            if (formatDateString(value,"yyyy-MM-dd") == jsonRCList[i].dateStr) { //点击2017年8月15日，弹出提示语
                theme += '<li style="text-align: left;"><div class="rcdiv">' + count + "、" + jsonRCList[i].theme + '</div></li>';
                count++;
            }
        }
        theme+="</ul>";
        $("#rcInfodiv").html(theme);
        var left = event.clientX;
        var top = event.clientY;
        $("#rcInfodiv").css("left", left+20);
        $("#rcInfodiv").css("top", top);

        if(count>1){
        $("#rcInfodiv").show();}
    });
    $(".laydate-day-mark").parent().mouseout(function () {
        $("#rcInfodiv").hide();
    });
}